package com.qf.hospital.controller;

import com.qf.hospital.VO.SideVO;
import com.qf.hospital.entity.SysUser;
import com.qf.hospital.service.SysUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 何星宇
 * @version V1.0
 * @Date 2021/10/16 10:14
 */
@RestController
public class SideController {

    @Autowired
    private SysUserService sysUserService;

    private Logger log = LoggerFactory.getLogger(SideController.class);

    @GetMapping("/menu/side")
    public List<SideVO> side(){
        //获取当前登录用户
        Subject subject = SecurityUtils.getSubject();
        SysUser sysUser = (SysUser) subject.getPrincipal();
        //校验
        if (sysUser==null){
            log.info("【侧边栏】 用户登录超时");
            return null;
        }

        //调用service查询数据
        List<SideVO> result = sysUserService.findSideByUserId(sysUser.getUserId());
        return result;
    }
}
